package io.github.wanggit.antrpc;

import io.github.wanggit.antrpc.client.monitor.IRpcCallLogHolder;
import io.github.wanggit.antrpc.client.spring.*;
import io.github.wanggit.antrpc.client.zk.IZkClient;
import io.github.wanggit.antrpc.client.zk.lb.ILoadBalancerContainer;
import io.github.wanggit.antrpc.client.zk.lb.LoadBalancerHelper;
import io.github.wanggit.antrpc.client.zk.listener.IListener;
import io.github.wanggit.antrpc.client.zk.register.IRegister;
import io.github.wanggit.antrpc.client.zk.register.IZkRegisterHolder;
import io.github.wanggit.antrpc.client.zk.zknode.INodeHostContainer;
import io.github.wanggit.antrpc.client.zk.zknode.IZkNodeCleaner;
import io.github.wanggit.antrpc.client.zk.zknode.IZkNodeOperator;
import io.github.wanggit.antrpc.commons.breaker.IResilience4jCircuitBreakerContainer;
import io.github.wanggit.antrpc.commons.codec.cryption.ICodecHolder;
import io.github.wanggit.antrpc.commons.codec.serialize.ISerializerHolder;
import io.github.wanggit.antrpc.commons.config.IConfiguration;
import io.github.wanggit.antrpc.commons.rate.IResilience4jRateLimiter;
import io.github.wanggit.antrpc.server.invoker.IRpcRequestBeanInvoker;
import org.springframework.context.ConfigurableApplicationContext;

public interface IAntrpcContext {

    ConfigurableApplicationContext getSpringApplicationContext();

    /**
     * 是否已初始化完成
     *
     * @return true inited
     */
    boolean isInited();

    CallerProxyFactory getCallerProxyFactory();

    CallerProxyMethodInterceptor getCallerProxyMethodInterceptor();

    IZkNodeCleaner getZkNodeCleaner();

    IZkNodeOperator getZkNodeOperator();

    ISerializerHolder getSerializerHolder();

    ICodecHolder getCodecHolder();

    IOnFailHolder getOnFailHolder();

    IResilience4jRateLimiter getClientResilience4jRateLimiterContainer();

    IResilience4jRateLimiter getServerResilience4jRateLimiterContainer();

    /**
     * 获取RpcClients
     *
     * @return RpcClients
     */
    IRpcClients getRpcClients();

    /**
     * 获取Cglib对象的容器
     *
     * @return Cglib动态对象的容器
     */
    BeanContainer getBeanContainer();

    /**
     * 获取配置对象
     *
     * @return 配置对象
     */
    IConfiguration getConfiguration();

    IResilience4jCircuitBreakerContainer getResilience4jCircuitBreakerContainer();

    IRpcCallLogHolder getRpcCallLogHolder();

    IZkClient getZkClient();

    IZkRegisterHolder getZkRegisterHolder();

    IRegister getRegister();

    ILoadBalancerContainer getLoadBalancerContainer();

    IRpcAutowiredProcessor getRpcAutowiredProcessor();

    IOnFailProcessor getOnFailProcessor();

    IListener getLbNodeChangeListener();

    IListener getRegisterNodeChangeListener();

    IListener getSubscribeNodeChangeListener();

    IListener getUnregNodeChangeListener();

    LoadBalancerHelper getLoadBalancerHelper();

    INodeHostContainer getNodeHostContainer();

    IRpcRequestBeanInvoker getRpcRequestBeanInvoker();

    /**
     * 初始化, 再设置完 {@link IConfiguration} 之后再进行初始化
     *
     * @param applicationContext Spring应用上下文
     */
    void init(ConfigurableApplicationContext applicationContext);

    void destroy();

    void restartTelnetServerIfRunning(
            IConfiguration configuration, ConfigurableApplicationContext applicationContext);

    void stopTelnetServerIfRunning(
            IConfiguration configuration, ConfigurableApplicationContext springApplicationContext);
}
